package com.lqq.chapter12;

import java.util.concurrent.CompletableFuture;

/**
 * @Author lqq677
 * @Date 2021/8/12 23:14
 * @Description 线程依赖, 先对一个数加 10,然后取平方
 */
public class CompletableFutureDemo4 {
    private static Integer num = 10;

    public static void main(String[] args) throws Exception {
        System.out.println("主线程开始");
        CompletableFuture<Integer> future =
                CompletableFuture.supplyAsync(() -> {
                    try {
                        System.out.println("加 10 任务开始");
                        num += 10;
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                    return num;
                }).thenApply(integer -> {
                    return num * num;
                });
        Integer integer = future.get();
        System.out.println("主线程结束, 子线程的结果为:" + integer);
    }
}
